package com.weilaiwd.upload.util;

import java.math.BigDecimal;
import java.util.UUID;

public class Lang {
	
	public static String getUUID() {
		return UUID.randomUUID().toString().replaceAll("-", "");
	}
	
	public static boolean isSameDirectory(String path1, String path2) {
		path1 = path1.replaceAll("\\\\", "").replaceAll("\\/", "");
		path2 = path2.replaceAll("\\\\", "").replaceAll("\\/", "");
		return path1.equals(path2);
	}
	
	public static String subFilePath(String path, String prefix) {
		path = path.replaceAll("\\\\", "\\/");
		prefix = prefix.replaceAll("\\\\", "\\/");
		return path.replaceFirst(prefix, "");
	}
	
	public static String getFormatSize(double size) {
		double kiloByte = size/1024;
		if(kiloByte < 1) {
			return size + "Byte(s)";
		}
		
		double megaByte = kiloByte/1024;
		if(megaByte < 1) {
			BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
			return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB";
		}
		
		double gigaByte = megaByte/1024;
		if(gigaByte < 1) {
			BigDecimal result2  = new BigDecimal(Double.toString(megaByte));
			return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "MB";
		}
		
		double teraBytes = gigaByte/1024;
		if(teraBytes < 1) {
			BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
			return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB";
		}
		BigDecimal result4 = new BigDecimal(teraBytes);
		return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB";
	}
	
	public static void main(String[] args) {
//		System.out.println(isSameDirectory("D:\\static", "D:/static/"));
//		System.out.println(subFilePath("D:\\static\\123\\fff", "D:/static/"));
		System.out.println("\u914d\u7f6e\u6587\u4ef6\u521d\u59cb\u5316\u5931\u8d25");
	}
	
}
